<template>
  <page-header-wrapper :title="false">
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input v-model="queryParam.queryCondition" allow-clear placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="日期">
                <a-range-picker v-model="queryParam.date" format="YYYY-MM-DD" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" :loading="loading" @click="handleSearch(queryParam)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :pagination="pagination"
        @change="handleTableChange"
        :columns="columns"
        :data-source="loadData"
      >
        <!-- <span slot="name" slot-scope="text, record">
          <template>
            <a-row :gutter="48">
              <a-col :md="4" :sm="24">
                订单ID{{ record.id }}
              </a-col>
             
            </a-row>
          </template>
        </span> -->
        <a-table
          slot="expandedRowRender" 
          slot-scope="record"
          :showHeader="false"
          :columns="innerColumns" 
          :data-source="record?.salDetailDtoList" 
          :pagination="false">
          <span slot="saleType" slot-scope="text, recod">
            <template>
              {{ recod.saleType == '0' ? '售出' :'退货' }}
            </template>
          </span>
          <span slot="details" slot-scope="text, recod">
            <template>
              <div>
                <div>串码1：{{ recod.phoneCode1 }}</div>
                <div>串码2：{{ recod.phoneCode2 }}</div>
              </div>
            </template>
          </span>
        </a-table>
      
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>
  
  <script>
import { getSalesStoreDetailListUsingPOST } from '@/api/api/qiantaizhangwu.ts'
import moment from 'moment'
import { omit } from 'lodash-es'
export default {
  name: 'SellRecordMyCreateOrderIndex',
  data() {
    return {
      mdl: null,
      visible: false,
      value: '',
      value4: '',
      confirmLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      pagination: {
        total: 0,
      },
      loading: false,
      queryParam: {
        pageNo: 1,
        pageSize: 10,
        queryCondition: '',
        date: [moment().startOf('months').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')],
        status: '',
      },
      // 表头
      columns: [
        {
          title: '商品',
          dataIndex: 'name',
          colspan: 5,
          customRender: (text, row, index) => {
          return  <div> <a-row gutter="48">
              <a-col md="4" sm="24">
                订单ID{ row.id} 
              </a-col>
             
            </a-row> </div>
        },
        },
        {
          title: '售价',
          dataIndex: '',
          colspan:0
        },
        {
          title: '类型',
          dataIndex: '',
          colspan:0
        },
        {
          title: '详情',
          dataIndex: '',
          colspan:0
        },
        {
          title: '付款方式',
          dataIndex: '',
          colspan:0
        },
      ],
      innerColumns:[{
          title: '商品',
          dataIndex: 'name',
        },
        {
          title: '售价',
          dataIndex: 'price',
        },
        {
          title: '类型',
          dataIndex: 'saleType',
          scopedSlots: { customRender: 'saleType' }
        },
        {
          title: '详情',
          dataIndex: 'details',
          scopedSlots: { customRender: 'details' }
        },
        {
          title: '付款方式',
          dataIndex: '',
        },],
      // 加载数据方法 必须为 Promise 对象
      loadData: [],
    }
  },
  mounted() {
    this.handleSearch(this.queryParam)
  },
  methods: {
    handleSearch(val) {
      this.loading = true
      const params = {
        ...val,
        empId: 1,
        storeId: this.$route.params.id,
        startTime: val?.date?.[0] ? moment(val?.date?.[0]).format('YYYY-MM-DD') : null,
        endTime: val?.date?.[1] ? moment(val?.date?.[1]).format('YYYY-MM-DD') : null,
      }
      getSalesStoreDetailListUsingPOST({ ...omit(params, ['date']) })
        .then((res) => {
          this.loadData = res.data.list
          this.loading = false
          this.queryParam.pageNo = this.pagination.current
          this.pagination = { ...this.pagination, total: Number(res.data.total) }
        })
        .catch((error) => {
          this.loading = false
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleTableChange(pagination, filters, sorter) {
      const pager = { ...this.pagination }
      pager.current = pagination.current
 pager.pageSize = pagination.pageSize
      this.pagination = pager
      this.handleSearch({
        sortField: sorter.field,
        sortOrder: sorter.order,
        ...filters,
        pageNo: pagination.current,
        pageSize: pagination.pageSize,
        queryCondition: this.queryParam.queryCondition,
        status: this.queryParam.status,
        date: this.queryParam.date,
      })
    },
  },
}
</script>